package com.woniuxy.ssm.listener;

import com.woniuxy.ssm.config.App;
import com.woniuxy.ssm.config.WebMvcConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @program: JavaEE-EFD
 * @description: web应用初始化器,应用启动时初始化的类
 * @author: fengjd
 * @create: 2022-07-29 09:57
 **/
public class WebInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext act = new AnnotationConfigWebApplicationContext();
        /* 和servlet整合 */
        act.register(App.class, WebMvcConfig.class);
        ServletRegistration.Dynamic dynamic = servletContext.addServlet("springmvc", new DispatcherServlet(act));
        dynamic.addMapping("/");
        dynamic.setLoadOnStartup(1);
    }


}
